package com.bobo.mm.socket;

import android.os.RemoteException;

import com.bobo.mm.ISocketListener;

import okhttp3.Response;

/**
 * Created by cocolove2 on 2020/5/15.
 */
public class InnerSocketListener {
    private ISocketListener mListener;

    InnerSocketListener(ISocketListener listener) {
        mListener = listener;
    }

    public void onOpen(String clientId, byte[] response) {
        try {
            if (mListener != null)
                mListener.onOpen(clientId, response);
        } catch (RemoteException e) {
            e.printStackTrace();
        }

    }

    public void onMessage(String clientId, byte[] message) {
        try {
            if (mListener != null) {
                mListener.onByteMessage(clientId, message);
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public void onMessage(String clientId, String message) {
        try {
            if (mListener != null) {
                mListener.onTextMessage(clientId, message);
            }
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public void onClosing(String clientId, int code, String msg) {
        try {
            if (mListener != null)
                mListener.onClosing(clientId, code, msg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public void onClosed(String clientId, int code, String msg) {
        try {
            if (mListener != null)
                mListener.onClosed(clientId, code, msg);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public void onFailure(String clientId, Throwable throwable, Response response) {
        try {
            if (mListener != null)
                mListener.onFailure(clientId, throwable.getClass().getName(), throwable.getMessage());
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

    public void onReconnecting(String clientId, int count) {
        try {
            if (mListener != null)
                mListener.onReconnecting(clientId, count);
        } catch (RemoteException e) {
            e.printStackTrace();
        }
    }

}
